'''
Description: 日志模块
Author: suyunzheng
Date: 2021-11-26 11:59:35
LastEditTime: 2021-11-26 12:14:51
LastEditors: maple
'''

from typing import Mapping
import numpy as np
import logging
import sys
import os
import glob

__all__ =  ['LOG']

class LOG():
    def __init__(self, log_config) -> None:
        level = log_config['level']                
        log_dir = log_config['log_dir']
        model_name = log_config['model_name']
        args = log_config['args']
        
        logger = logging.getLogger("Model")

        logger.setLevel(level)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        file_handler = logging.FileHandler('%s/%s.log' % (log_dir, model_name))
        file_handler.setLevel(level)
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)
        self.logger = logger
        self.log_string("PARAMETER ...")
        self.log_string(args)

    # @staticmethod
    def log_string(self, str):
        self.logger.info(str)
        print(str)

if __name__ == "__main__":
    log_config = {
        'level':logging.INFO,
        'log_dir':'./',
        'model_name':'spvcnn',
        'args':None
    }
    log = LOG(log_config=log_config)
    log.log_string("hello, log")
